<!--# 
layout("/layout/default.html",{"menu":["codebook","codebook_list"],"breadcrumbs":[{"name":"数据列表",url:"codebook/list"},{"name":(obj.data.data==null?"添加数据":"编辑数据")}]}){ 
 #-->
<div class="space-4"></div>
<div class="row">
	<div class="col-md-8 col-md-offset-2 col-sm-12">
		<div class="panel panel-info">
			<div class="panel-heading">
				<h3 class="panel-title">${obj.data.data==null ? "添加数据":"编辑数据"}</h3>
			</div>
			<div class="panel-body">
				<form id="adddataForm" class="cmxform form-horizontal adminex-form" novalidate="novalidate">
					<div class="form-group ">
						<label for="分组名" class="control-label col-lg-3">数据分组 : </label>
						<div class="col-lg-9">
							<select class="form-control" name="groupId" id="groupId" ${obj.data.data!=null?'disabled':''}>
								<!--# for(group in obj.data.groups) { #-->
								<option value="${group.id!}" ${null !=obj.data.data && obj.data.data.groupId==group.id?'selected' : ''}>${group.name!}</option>
								<!--# } #-->
							</select>
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 级联上级 : </label>
						<div class="col-lg-9">
							<div class="input-group" onclick="showCodeBookSelector()">
								<input class="form-control " type="text" id="parentName" disabled="disabled" placeholder="不选默认为无级联数据" value="${obj.data.parent.name!}"> <span
									class="input-group-btn">
									<button class="btn btn-sm btn-primary" type="button">
										<i class="ace-icon fa fa-plus bigger-110"></i> 选择
									</button>
								</span> <input type="text" class="hide" id="parentId" name="parentId" value="${obj.data.data.parentId!}">
							</div>
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 数据key : </label>
						<div class="col-lg-9">
							<input class="form-control" ${obj.data.data!=null? 'readonly':''}  type="text" placeholder="请输入数据key" name="name" data-type='required' data-error='请输入数据key'
								value="${obj.data.data.name!}">
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 数据值 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="text" placeholder="请输入数据值" name="value" data-type='required' data-error='请输入数据值' value="${obj.data.data.value!}">
						</div>
					</div>
					<div class="form-group ">
						<label class="control-label col-lg-3"> 数据序号 : </label>
						<div class="col-lg-9">
							<input class="form-control" type="number" placeholder="请输入数据序号" name="index" data-type='required' data-error='请输入数据序号' value="${obj.data.data.index!}">
						</div>
					</div>

					<input type="text" class="hide" id="id" name="id" value="${obj.data.data.id!}">
					<div class="pull-right" style="margin-right: 45px">
						<button type="button" class="btn btn-sm btn-primary" onclick="save(this)">
							<i class="fa fa-save"></i> 提交
						</button>
						<button class="btn btn-sm btn-default btn-back">
							<i class="fa fa-undo"></i> 返回
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	function showCodeBookSelector() {
		var groupId = $('#groupId').val();
		layer.open({
			type : 2,
			title : '码本数据选择器',
			fix : false,
			closeBtn : false,
			move : false,
			area : [ '600px', '450px' ],
			content : getRootPath() + '/codebook/selector/' + groupId,
			btn : [ '确认', '取消' ],
			yes : function(index, layero) {
				if (layer.getChildFrame('#data', index).val()) {
					var result = $.parseJSON(layer.getChildFrame('#data', index).val());
					console.log(result);
					$('#parentName').val(result.name);
					$('#parentId').val(result.id);
				}
				layer.close(index);
			},
			cancel : function(index) {
				layer.close(index);
			}
		});
	}
	function save(btn) {
		if ($('#adddataForm').find('input').validation()) { //验证表单
			if ($('#id').val()) {
				$.post(getRootPath() + '/codebook/edit', $('#adddataForm').serialize(), function(result) {
					if (result.operationState == 'SUCCESS') {
						location.href = getRootPath() + "/codebook/list";
					} else {
						validationFail(result.data.reason, btn);
					}
				}, 'json');
			} else {
				$.post(getRootPath() + '/codebook/add', $('#adddataForm').serialize(), function(result) {
					if (result.operationState == 'SUCCESS') {
						location.href = getRootPath() + "/codebook/list";
					} else {
						validationFail(result.data.reason, btn);
					}
				}, 'json');
			}
		}
	}
</script>
<!--# } #-->